package com.ruoyi.project.service.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.domain.ProProject;
import com.ruoyi.project.mapper.ProProjectMapper;
import com.ruoyi.project.service.IProProjectService;

/**
 * 项目基本信息Service业务层处理
 * 
 * @author phil
 * @date 2020-05-28
 */
@Service
public class ProProjectServiceImpl implements IProProjectService{

	private static final Logger log = LoggerFactory.getLogger(ProProjectServiceImpl.class);

	@Autowired
	private ProProjectMapper proProjectMapper;

	/**
	 * 查询项目基本信息
	 * 
	 * @param projectId 项目基本信息ID
	 * @return 项目基本信息
	 */
	@Override
	public ProProject selectProProjectById(Long projectId){
		return proProjectMapper.selectProProjectById(projectId);
	}

	/**
	 * 查询项目基本信息列表
	 * 
	 * @param proProject 项目基本信息
	 * @return 项目基本信息
	 */
	@Override
	public List<ProProject> selectProProjectList(ProProject proProject){
		return proProjectMapper.selectProProjectList(proProject);
	}

	/**
	 * 新增项目基本信息
	 * 
	 * @param proProject 项目基本信息
	 * @return 结果
	 */
	@Override
	public int insertProProject(ProProject proProject){
		proProject.setCreateTime(DateUtils.getNowDate());
		return proProjectMapper.insertProProject(proProject);
	}

	/**
	 * 修改项目基本信息
	 * 
	 * @param proProject 项目基本信息
	 * @return 结果
	 */
	@Override
	public int updateProProject(ProProject proProject){
		proProject.setUpdateTime(DateUtils.getNowDate());
		return proProjectMapper.updateProProject(proProject);
	}

	/**
	 * 删除项目基本信息对象
	 * 
	 * @param ids 需要删除的数据ID
	 * @return 结果
	 */
	@Override
	public int deleteProProjectByIds(String ids){
		return proProjectMapper.deleteProProjectByIds(Convert.toStrArray(ids));
	}

	/**
	 * 删除项目基本信息信息
	 * 
	 * @param projectId 项目基本信息ID
	 * @return 结果
	 */
	@Override
	public int deleteProProjectById(Long projectId){
		return proProjectMapper.deleteProProjectById(projectId);
	}

	/**
	 * 获取可派单项目列表
	 * 
	 * @param project
	 * @return
	 */
	@Override
	public List<Map<String, Object>> getMyDispatchProjectList(ProProject project){
		return proProjectMapper.getMyDispatchProjectList(project);
	}

	@Override
	@Transactional
	public int insertProProjects(List<ProProject> projectList){
		int resultCount = 0;
		if(projectList != null && projectList.size() > 0){
			for(ProProject project : projectList){
				resultCount += proProjectMapper.insertProProject(project);
			}
		}
		return resultCount;
	}

}
